package com.sugon.ww

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD


object Oper4 {


  def main(args: Array[String]): Unit = {


    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("map")

    val sc = new SparkContext(conf)

    val listRDD: RDD[Int] = sc.makeRDD(1 to 16, 4)
    //
    //    val unit: RDD[Int] = listRDD.mapPartitions(f=>List(f.max).toIterator)
    //
    //    unit.collect().foreach(println)



    println(listRDD.partitions.size)

    /**
      * 取最大值
      */
    val maxValue = listRDD.glom().map((value:Array[Int]) => value.max)
      .reduce(_ max _)

    println(maxValue)


    val value: RDD[Int] = listRDD.coalesce(3)

//    val unit: RDD[(Int, Iterable[Int])] = listRDD.groupBy(i=>i%2)

//    unit.collect().foreach(println)

    println(value.partitions.size)


  }
}
